<?php

/*
 * Action 5$
 *
 * Play this as if it were an Action card in the Supply costing less than it that you choose. This is that card until it leaves play.
 */

class BandofMisfits extends Card implements iAction, iKingdom, iDarkAges, iDuration {

    public function __construct() {
        parent::__construct("Band of Misfits", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Play this as if it were an Action card in the Supply costing less than it that you choose. This is that card until it leaves play.");
    }
    
    public function startTurn(Game $game, $quantity) {
        if ($quantity > 0)
            return RETURN_DURATION_TO_DISCARD;
        else
            return DELETE_VIRTUAL_DURATION_CARD;
    }
    
    public function cleanup(Game $game) {
        $db = DBUtils::Create();
        $this->duration = $db->loadCardData($game->getId(), $game->getPlayerName(), $this->getKey());
        if ($this->duration != 0) {
            $game->moveCardFromPileToPile($this, PlayArea, DurationPileCards);
        }
        $db->deleteCardData($game->getId(), $game->getPlayerName(), $this->getKey());
    }

    public function play(Game $game, $isRealCard) {
        
        
        $coins = $this->getPrice($game)->getCoins();
        $kingdomCards = $game->getAllBoardCardsByPrice(0, $coins);
        $action_cards = array();
        foreach ($kingdomCards as $card) {
            if ($card instanceof iAction) {
                $action_cards[] = $card;
            }
        }

        if (sizeof($action_cards) > 0) {

            $output = MySocket::GetUserReply($game, Input_ChooseOne, $action_cards, 1, 1, null, "Choose a card to activate");
            if (sizeof($output) > 0) {
                $card = n2c($output[0]);
                
                ScreenDisplay::addScreenMessage($game, true, "activate " . nicePrint($card), " activates " . ScreenDisplay::$LMSG);
                $game->pushCardToStack($card, VIRTUAL_CARD);
                
                $this->duration = $card->getDuration();
                
                #saving the duration into db
                $db = DBUtils::Create();
                $db->saveCardData($game->getId(), $game->getPlayerName(), $this->getKey(), $this->duration);
                
                if ($this->duration != 0) {
                    $game->pushCardToDurationAffects($this, $this->duration, $isRealCard);
                }
            }
        }
        $game->cardActionFinished();
        return true;
    }

}

?>